using System;
using System.Collections;

namespace Slaks.Graphs.Comparators
{
	public class FuzzyFrequencyComparer : IComparer
	{
		public int Compare(Vertex x, Vertex y)
		{
			long countEdgesX = x.CountEdges();
			long countEdgesY = y.CountEdges();
			double xFreq = x.Frequency + countEdgesX;
			double yFreq = y.Frequency + countEdgesY;

			if (xFreq > yFreq) return -1;
			else if (xFreq == yFreq) return 0;
			return 1;
		}

		public int Compare(object x, object y)
		{
			Vertex xx = x as Vertex;
			Vertex yy = y as Vertex;
			if (xx == null || yy == null) throw new ArgumentException("Object passed for comparison is not Vertex");
			return Compare(xx, yy);
		}
	}
}